<template>
	<div class="home-container layout-pd">
    <h4>
      <p style="margin-bottom: 20px">伊莱特库存盘点首页</p>
      <el-button size="default" type="danger" class="ml5" :loading="state.sstbLoading" @click="shuJuTongBu"  v-auths="[state.permissionType.sysAdmin, state.permissionType.cs_shujutongbu]"  >
        <el-icon><ele-Document /></el-icon>数据同步
      </el-button>
      <BR /><BR />
      <el-button size="default" type="danger" class="ml5" @click="logout" >
        <el-icon><ele-Document /></el-icon>退出登录
      </el-button>
    </h4>
	</div>
</template>

<script setup name="kcpdHomeIndex">
import request from '/@/utils/request';
import { ElMessage } from 'element-plus';
import PermissionType from "/@/utils/PermissionType";
import {reactive, ref, onMounted, onUnmounted, defineAsyncComponent} from "vue";
import {Session} from "/@/utils/storage";
import { useRouter } from 'vue-router';
const router = useRouter();

const state = reactive({
  permissionType:PermissionType,
  sstbLoading : false,
})
const shuJuTongBu = ()=>{
  state.sstbLoading = true;
  request({
    url: '/currentstore/shujutongbu',
    timeout: 5000000,
    data: {}
  }).then(res => {
    state.sstbLoading = false;
    if(res.code !== "200"){
      ElMessage.error(res.msg)
    }else{
      ElMessage.success("插入" + res.data.insertcount + "条,修改" + res.data.updatecount + "条,异常" + res.data.exceptioncount + "条" );
    }
  })
}
const logout = ()=>{
  // 清除缓存/token等
  Session.clear();
  // 使用 reload 时，不需要调用 resetRoute() 重置路由
  router.push("/login")
}
</script>
<style scoped lang="scss">
.home-container {
  h4{
    width: 200px;
    margin: 0 auto;
    font-weight: 600;
    font-size: 20px;
    color: #3c3c3c;
  }
}
</style>
